//ui控制脚本
cc.Class({
    extends: cc.Component,

    properties: {
        //UI数组
        Arr_Ui: {
            default: [],
            type: cc.Node
        },
        //[开始/重新]UI节点起始位置
        StartUI_Start: cc.p(0,0),
        //[开始/重新]UI节点结束位置
        StartUI_End: cc.p(0,0),
        //[结束]UI节点起始位置
        EndUI_Start: cc.p(0,0),
        //[结束]UI节点结束位置
        EndUI_End: cc.p(0,0),
        //[提示]UI节点起始位置
        TipsUI_Start: cc.p(0,0),
        //[提示]UI节点结束位置
        TipsUI_End: cc.p(0,0),

    },

    onLoad () {

    },

    // update (dt) {},

    //节点移动方法
    //[time：运动时间  pos：运动位置]
    action_node(time,pos) {
        var action = cc.moveTo(time,pos);
        return action;
    },
    
    //开始按钮回调函数
    startbtn_callback () {
        var state = Game.State;
        if(state == GameState.End) {
            //若当前游戏状态为结束状态,则变为开始游戏状态
            Game.State = GameState.Start;
            this.ui_totalaction("end",this.Arr_Ui);
        }
    },
    
    //重新按钮回调函数
    repeatbtn_callback () {
        var state = Game.State;
        if(state == GameState.End) {
            //若当前游戏状态为结束状态,则变为开始游戏状态
            Game.State = GameState.Start;
            Game.Self.getComponent("game").repeat_game();
            this.ui_totalaction("start",this.Arr_Ui);
        }
    },

    //显示结果界面
    show_result() {
        var text = this.Arr_Ui[UI_Node.END].children;
        var action = cc.moveTo(0.5,this.EndUI_End);
        this.Arr_Ui[UI_Node.END].runAction(action);
        text[0].getComponent(cc.Label).string = Texts.Te_one + Game.Count + Texts.Te_two;
    },

    //游戏ui的总体运动
    //[type:动作类型 ui_arr:ui节点数组]
    ui_totalaction (type,ui_arr) {
        var name = "";
        var len = ui_arr.length;
        for(var i = 0; i < len; i++) {
            var temp = null;
            name = ui_arr[i].name + "_" + type;
            switch(name){
                case "End_start":
                    temp = this.action_node(0.5,this.EndUI_Start);
                break;
                case "Start_Ui_end":
                    temp = this.action_node(0.5,this.StartUI_End);
                break;
                case "End_end":
                    temp = this.action_node(0.5,this.EndUI_Start);
                break;
                case "Tips_end":
                    temp = this.action_node(0.5,this.TipsUI_End);
                break;
            }
            if(temp != null)
            ui_arr[i].runAction(temp);
        }
    }
});
